﻿@using SimpleIdServer.IdServer.Website.Resources;
@using SimpleIdServer.IdServer.Website.Stores.RealmStore;
@inject IState<RealmsState> realmsState
@inject IDispatcher dispatcher
@inject NavigationManager navigationManager
@inject Radzen.DialogService dialogService
@inject IUrlHelper urlHelper

<RadzenTemplateForm Submit=@SubmitSelectRealm TItem="RealmForm" Data=@realmForm>
    <!-- Realm -->
    <RadzenText TextStyle="TextStyle.Subtitle2" TagName="TagName.H3">@Global.Realm</RadzenText>
    <RadzenDropDown Name="Realm" Class="w-100"
                    Data=@realmsState.Value.Realms
                    TValue="string"
                    @bind-Value=@realmForm.Name
                    TextProperty="Name" ValueProperty="Name"></RadzenDropDown>
    <RadzenButton class="mt-1" Variant="Variant.Flat" ButtonType="ButtonType.Submit" ButtonStyle="ButtonStyle.Success" Text="@Global.Select"  />
</RadzenTemplateForm>

@code {
    [Parameter]
    public string activeRealm { get; set; }

    record RealmForm
    {
        public string Name { get; set; }
    }

    RealmForm realmForm = new RealmForm();

    protected override void OnParametersSet()
    {
        base.OnParametersSet();
        realmForm.Name = activeRealm;
    }

    void SubmitSelectRealm(RealmForm realm)
    {
        navigationManager.NavigateTo($"/{realm.Name}/realm/overview", true);
    }
}